home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / SIEVECLI.FRM < prev    next >
Text File  |  1997-06-14  |  26KB  |  706 lines

  1. VERSION 5.00
  2. Object = "{B4A64CE4-D292-11D0-B253-00AA005754FD}#1.0#0"; "SIEVEBASCTLP.OCX"
  3. Object = "{04C14C62-BFAC-11D0-B253-00AA005754FD}#1.0#0"; "SIEVEBASCTLN.OCX"
  4. Begin VB.Form FSieveClient 
  5.    Caption         =   "Sieve of Eratosthenes Client"
  6.    ClientHeight    =   2715
  7.    ClientLeft      =   3000
  8.    ClientTop       =   1725
  9.    ClientWidth     =   5610
  10.    Icon            =   "sievecli.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    PaletteMode     =   1  'UseZOrder
  13.    ScaleHeight     =   2715
  14.    ScaleWidth      =   5610
  15.    Begin SieveBasCtlN.XSieveN sieveCtlN 
  16.       Height          =   540
  17.       Left            =   240
  18.       TabIndex        =   16
  19.       Top             =   2040
  20.       Width           =   540
  21.       _ExtentX        =   953
  22.       _ExtentY        =   953
  23.    End
  24.    Begin SieveBasCtlP.XSieveP sieveCtlP 
  25.       Height          =   540
  26.       Left            =   240
  27.       TabIndex        =   15
  28.       Top             =   1320
  29.       Width           =   540
  30.       _ExtentX        =   953
  31.       _ExtentY        =   953
  32.    End
  33.    Begin VB.ComboBox cboServer 
  34.       Height          =   288
  35.       ItemData        =   "sievecli.frx":0CFA
  36.       Left            =   1596
  37.       List            =   "sievecli.frx":0D22
  38.       Style           =   2  'Dropdown List
  39.       TabIndex        =   14
  40.       Top             =   2040
  41.       Width           =   2760
  42.    End
  43.    Begin VB.CheckBox chkAll 
  44.       Caption         =   "Get All"
  45.       Height          =   255
  46.       Left            =   3600
  47.       TabIndex        =   13
  48.       Top             =   2388
  49.       Width           =   828
  50.    End
  51.    Begin VB.CheckBox chkLate 
  52.       Caption         =   "Late Bind"
  53.       Height          =   255
  54.       Left            =   2556
  55.       TabIndex        =   12
  56.       Top             =   2388
  57.       Width           =   975
  58.    End
  59.    Begin VB.ListBox lstOutput 
  60.       Height          =   2010
  61.       Left            =   4440
  62.       TabIndex        =   11
  63.       Top             =   120
  64.       Width           =   972
  65.    End
  66.    Begin VB.CheckBox chkDisplay 
  67.       Caption         =   "Display"
  68.       Height          =   255
  69.       Left            =   1596
  70.       TabIndex        =   10
  71.       Top             =   2388
  72.       Width           =   888
  73.    End
  74.    Begin VB.TextBox txtTime 
  75.       Height          =   372
  76.       Left            =   2880
  77.       TabIndex        =   8
  78.       Top             =   1560
  79.       Width           =   1452
  80.    End
  81.    Begin VB.TextBox txtPrimes 
  82.       Height          =   372
  83.       Left            =   2880
  84.       TabIndex        =   6
  85.       Top             =   1080
  86.       Width           =   1452
  87.    End
  88.    Begin VB.TextBox txtMaxPrime 
  89.       Height          =   372
  90.       Left            =   2880
  91.       TabIndex        =   3
  92.       Text            =   " 5000"
  93.       Top             =   600
  94.       Width           =   1452
  95.    End
  96.    Begin VB.TextBox txtIterate 
  97.       Height          =   372
  98.       Left            =   2880
  99.       TabIndex        =   2
  100.       Text            =   "5"
  101.       Top             =   120
  102.       Width           =   1452
  103.    End
  104.    Begin VB.CommandButton cmdExit 
  105.       Cancel          =   -1  'True
  106.       Caption         =   "E&xit"
  107.       Height          =   495
  108.       Left            =   120
  109.       TabIndex        =   1
  110.       Top             =   720
  111.       Width           =   1215
  112.    End
  113.    Begin VB.CommandButton cmdSieve 
  114.       Caption         =   "&Sieve"
  115.       Default         =   -1  'True
  116.       Height          =   495
  117.       Left            =   108
  118.       TabIndex        =   0
  119.       Top             =   120
  120.       Width           =   1215
  121.    End
  122.    Begin VB.Label lbl 
  123.       Caption         =   "Time (ms):"
  124.       Height          =   375
  125.       Index           =   3
  126.       Left            =   1560
  127.       TabIndex        =   9
  128.       Top             =   1560
  129.       Width           =   1215
  130.    End
  131.    Begin VB.Label lbl 
  132.       Caption         =   "Primes:"
  133.       Height          =   375
  134.       Index           =   2
  135.       Left            =   1560
  136.       TabIndex        =   7
  137.       Top             =   1080
  138.       Width           =   1215
  139.    End
  140.    Begin VB.Label lbl 
  141.       Caption         =   "Maximum Prime:"
  142.       Height          =   375
  143.       Index           =   1
  144.       Left            =   1560
  145.       TabIndex        =   5
  146.       Top             =   600
  147.       Width           =   1215
  148.    End
  149.    Begin VB.Label lbl 
  150.       Caption         =   "Iterations:"
  151.       Height          =   375
  152.       Index           =   0
  153.       Left            =   1560
  154.       TabIndex        =   4
  155.       Top             =   120
  156.       Width           =   1215
  157.    End
  158. End
  159. Attribute VB_Name = "FSieveClient"
  160. Attribute VB_GlobalNameSpace = False
  161. Attribute VB_Creatable = False
  162. Attribute VB_PredeclaredId = True
  163. Attribute VB_Exposed = False
  164. Option Explicit
  165.  
  166. Enum ESieveType
  167.     estBasicLocalFunction
  168.     estBasicLocalClass
  169.     estBasicGlobalFunctionP
  170.     estBasicGlobalFunctionN
  171.     estBasicDllPCode
  172.     estBasicDllNative
  173.     estBasicCtlPCode
  174.     estBasicCtlNative
  175.     estBasicExePCode
  176.     estBasicExeNative
  177.     estCppATL
  178.     estCppMFC
  179. End Enum
  180.  
  181. Private Declare Function timeGetTime Lib "winmm" () As Long
  182.  
  183. Private fDisplay As Boolean
  184. Private dx As Long, dxOut As Long
  185.  
  186. Private Sub Form_Load()
  187.     cboServer.Text = cboServer.List(0)
  188.     dxOut = lstOutput.Left + Width - ScaleWidth
  189.     dx = Width
  190.     Width = dxOut
  191. End Sub
  192.  
  193. Private Sub cboServer_Click()
  194.     Select Case cboServer.ListIndex
  195.     Case estBasicLocalFunction
  196.         chkAll.Enabled = False
  197.         chkAll.Value = vbUnchecked
  198.         chkLate.Enabled = False
  199.     Case estBasicCtlPCode, estBasicCtlNative
  200.         chkLate.Enabled = False
  201.         chkLate.Value = vbUnchecked
  202.         chkAll.Enabled = True
  203.     Case estBasicGlobalFunctionP, estBasicGlobalFunctionN
  204.         chkLate.Enabled = False
  205.         chkLate.Value = vbUnchecked
  206.         chkAll.Enabled = False
  207.         chkLate.Value = vbUnchecked
  208.     Case Else
  209.         chkAll.Enabled = True
  210.         chkLate.Enabled = True
  211.     End Select
  212. End Sub
  213.  
  214. Private Sub chkDisplay_Click()
  215.     Static cLastIter As Integer
  216.     If cLastIter = 0 Then cLastIter = txtIterate.Text
  217.     fDisplay = (chkDisplay.Value = vbChecked)
  218.     If fDisplay Then
  219.         txtIterate.Text = 1
  220.         Width = dx
  221.     Else
  222.         txtIterate.Text = cLastIter
  223.         Width = dxOut
  224.     End If
  225. End Sub
  226.  
  227. Private Sub cmdExit_Click()
  228.     Unload Me
  229. End Sub
  230.  
  231. Private Sub cmdSieve_Click()
  232.     Dim ms As Long, i As Integer, iPrime As Integer, cPrime As Integer
  233.     Dim ai() As Integer, vai As Variant
  234.        
  235.     ' Initialize prime variables
  236.     Dim iMaxPrime As Integer, cIter As Integer, cPrimeMax As Integer
  237.     iMaxPrime = txtMaxPrime.Text
  238.     cIter = txtIterate.Text
  239.     cPrimeMax = txtMaxPrime.Text
  240.     txtTime.Text = ""
  241.     txtPrimes.Text = ""
  242.     txtTime.Refresh
  243.     txtPrimes.Refresh
  244.     
  245.     Dim mpcMouse As MousePointerConstants
  246.     mpcMouse = MousePointer
  247.     MousePointer = vbHourglass
  248.     
  249.     ' Default early binding
  250.     If chkLate = vbUnchecked Then
  251.         Select Case cboServer.ListIndex
  252.         Case estBasicLocalFunction
  253.             ' Get all at once
  254.             ms = timeGetTime()
  255.             For i = 1 To cIter
  256.                 ReDim ai(0 To cPrimeMax)
  257.                 cPrime = Sieve(ai())
  258.                 If fDisplay Then
  259.                     lstOutput.Clear
  260.                     For iPrime = 0 To cPrime - 1
  261.                         lstOutput.AddItem ai(iPrime)
  262.                         lstOutput.TopIndex = lstOutput.ListCount - 1
  263.                         lstOutput.Refresh
  264.                     Next
  265.                 End If
  266.             Next
  267.             txtTime.Text = timeGetTime() - ms
  268.             txtPrimes.Text = cPrime
  269.         Case estBasicLocalClass
  270.             ' Basic local class
  271.             Dim sieveLocal As New CSieve
  272.             sieveLocal.MaxPrime = txtMaxPrime.Text
  273.             If chkAll = vbUnchecked Then
  274.                 ' Get one at a time
  275.                 ms = timeGetTime()
  276.                 For i = 1 To cIter
  277.                     sieveLocal.ReInitialize
  278.                     Do
  279.                         iPrime = sieveLocal.NextPrime
  280.                         If fDisplay And iPrime Then
  281.                             lstOutput.AddItem iPrime
  282.                             lstOutput.TopIndex = lstOutput.ListCount - 1
  283.                             lstOutput.Refresh
  284.                         End If
  285.                     Loop Until iPrime = 0
  286.                 Next
  287.                 txtTime.Text = timeGetTime() - ms
  288.                 txtPrimes.Text = sieveLocal.Primes
  289.             Else
  290.                 ' Get all at once
  291.                 ms = timeGetTime()
  292.                 For i = 1 To cIter
  293.                     ReDim ai(0 To cPrimeMax)
  294.                     sieveLocal.AllPrimes ai()
  295.                     If fDisplay Then
  296.                         For iPrime = 0 To sieveLocal.Primes - 1
  297.                             lstOutput.AddItem ai(iPrime)
  298.                         Next
  299.                     End If
  300.                 Next
  301.                 txtTime.Text = timeGetTime() - ms
  302.                 txtPrimes.Text = sieveLocal.Primes
  303.             End If
  304.         Case estBasicGlobalFunctionP
  305.             ' Global function
  306.             ms = timeGetTime()
  307.             For i = 1 To cIter
  308.                 ReDim ai(0 To cPrimeMax)
  309.                 cPrime = SieveBasGlobP.SieveGlobal(ai())
  310.                 If fDisplay Then
  311.                     lstOutput.Clear
  312.                     For iPrime = 0 To cPrime - 1
  313.                         lstOutput.AddItem ai(iPrime)
  314.                     Next
  315.                 End If
  316.             Next
  317.             txtTime.Text = timeGetTime() - ms
  318.             txtPrimes.Text = cPrime
  319.         Case estBasicGlobalFunctionN
  320.             ' Global function
  321.             ms = timeGetTime()
  322.             For i = 1 To cIter
  323.                 ReDim ai(0 To cPrimeMax)
  324.                 cPrime = SieveBasGlobN.SieveGlobal(ai())
  325.                 If fDisplay Then
  326.                     lstOutput.Clear
  327.                     For iPrime = 0 To cPrime - 1
  328.                         lstOutput.AddItem ai(iPrime)
  329.                     Next
  330.                 End If
  331.             Next
  332.             txtTime.Text = timeGetTime() - ms
  333.             txtPrimes.Text = cPrime
  334.         Case estBasicDllPCode
  335.             ' Basic p-code DLL version, early bind
  336.             Dim SieveBasDllP As New CSieveBasDllP
  337.             SieveBasDllP.MaxPrime = txtMaxPrime.Text
  338.             If chkAll = vbUnchecked Then
  339.                 ' Get one at a time
  340.                 ms = timeGetTime()
  341.                 For i = 1 To cIter
  342.                     SieveBasDllP.ReInitialize
  343.                     Do
  344.                         iPrime = SieveBasDllP.NextPrime
  345.                         If fDisplay And iPrime Then
  346.                             lstOutput.AddItem iPrime
  347.                             lstOutput.TopIndex = lstOutput.ListCount - 1
  348.                             lstOutput.Refresh
  349.                         End If
  350.                     Loop Until iPrime = 0
  351.                 Next
  352.                 txtTime.Text = timeGetTime() - ms
  353.                 txtPrimes.Text = SieveBasDllP.Primes
  354.             Else
  355.                 ' Get all at once
  356.                 ms = timeGetTime()
  357.                 For i = 1 To cIter
  358.                     ReDim ai(0 To cPrimeMax)
  359.                     SieveBasDllP.AllPrimes ai()
  360.                     If fDisplay Then
  361.                         For iPrime = 0 To SieveBasDllP.Primes - 1
  362.                             lstOutput.AddItem ai(iPrime)
  363.                         Next
  364.                     End If
  365.                 Next
  366.                 txtTime.Text = timeGetTime() - ms
  367.                 txtPrimes.Text = SieveBasDllP.Primes
  368.             End If
  369.         Case estBasicDllNative
  370.             ' Basic DLL version, early bind
  371.             Dim SieveBasDllN As New CSieveBasDllN
  372.             SieveBasDllN.MaxPrime = txtMaxPrime.Text
  373.             If chkAll = vbUnchecked Then
  374.                 ' Get one at a time
  375.                 ms = timeGetTime()
  376.                 For i = 1 To cIter
  377.                     SieveBasDllN.ReInitialize
  378.                     Do
  379.                         iPrime = SieveBasDllN.NextPrime
  380.                         If fDisplay And iPrime Then
  381.                             lstOutput.AddItem iPrime
  382.                             lstOutput.TopIndex = lstOutput.ListCount - 1
  383.                             lstOutput.Refresh
  384.                         End If
  385.                     Loop Until iPrime = 0
  386.                 Next
  387.                 txtTime.Text = timeGetTime() - ms
  388.                 txtPrimes.Text = SieveBasDllN.Primes
  389.             Else
  390.                 ' Get all at once
  391.                 ms = timeGetTime()
  392.                 For i = 1 To cIter
  393.                     ReDim ai(0 To cPrimeMax)
  394.                     SieveBasDllN.AllPrimes ai()
  395.                     If fDisplay Then
  396.                         For iPrime = 0 To SieveBasDllN.Primes - 1
  397.                             lstOutput.AddItem ai(iPrime)
  398.                         Next
  399.                     End If
  400.                 Next
  401.                 txtTime.Text = timeGetTime() - ms
  402.                 txtPrimes.Text = SieveBasDllN.Primes
  403.             End If
  404.         Case estBasicCtlPCode
  405.             ' Basic p-code control version
  406.             sieveCtlP.MaxPrime = txtMaxPrime.Text
  407.             If chkAll = vbUnchecked Then
  408.                 ' Get one at a time
  409.                 ms = timeGetTime()
  410.                 For i = 1 To cIter
  411.                     sieveCtlP.ReInitialize
  412.                     Do
  413.                         iPrime = sieveCtlP.NextPrime
  414.                         If fDisplay And iPrime Then
  415.                             lstOutput.AddItem iPrime
  416.                             lstOutput.TopIndex = lstOutput.ListCount - 1
  417.                             lstOutput.Refresh
  418.                         End If
  419.                     Loop Until iPrime = 0
  420.                 Next
  421.                 txtTime.Text = timeGetTime() - ms
  422.                 txtPrimes.Text = sieveCtlP.Primes
  423.             Else
  424.                 ' Get all at once
  425.                 ms = timeGetTime()
  426.                 For i = 1 To cIter
  427.                     ReDim ai(0 To cPrimeMax)
  428.                     sieveCtlP.AllPrimes ai()
  429.                     If fDisplay Then
  430.                         For iPrime = 0 To sieveCtlP.Primes - 1
  431.                             lstOutput.AddItem ai(iPrime)
  432.                         Next
  433.                     End If
  434.                 Next
  435.                 txtTime.Text = timeGetTime() - ms
  436.                 txtPrimes.Text = sieveCtlP.Primes
  437.             End If
  438.         Case estBasicCtlNative
  439.             ' Basic native control version
  440.             sieveCtlN.MaxPrime = txtMaxPrime.Text
  441.             If chkAll = vbUnchecked Then
  442.                 ' Get one at a time
  443.                 ms = timeGetTime()
  444.                 For i = 1 To cIter
  445.                     sieveCtlN.ReInitialize
  446.                     Do
  447.                         iPrime = sieveCtlN.NextPrime
  448.                         If fDisplay And iPrime Then
  449.                             lstOutput.AddItem iPrime
  450.                             lstOutput.TopIndex = lstOutput.ListCount - 1
  451.                             lstOutput.Refresh
  452.                         End If
  453.                     Loop Until iPrime = 0
  454.                 Next
  455.                 txtTime.Text = timeGetTime() - ms
  456.                 txtPrimes.Text = sieveCtlN.Primes
  457.             Else
  458.                 ' Get all at once
  459.                 ms = timeGetTime()
  460.                 For i = 1 To cIter
  461.                     ReDim ai(0 To cPrimeMax)
  462.                     sieveCtlN.AllPrimes ai()
  463.                     If fDisplay Then
  464.                         For iPrime = 0 To sieveCtlN.Primes - 1
  465.                             lstOutput.AddItem ai(iPrime)
  466.                         Next
  467.                     End If
  468.                 Next
  469.                 txtTime.Text = timeGetTime() - ms
  470.                 txtPrimes.Text = sieveCtlN.Primes
  471.             End If
  472.         Case estBasicExePCode
  473.             ' Basic p-code EXE version, early bind
  474.             Dim sieveBasExeP As New CSieveBasExeP
  475.             sieveBasExeP.MaxPrime = txtMaxPrime.Text
  476.             If chkAll = vbUnchecked Then
  477.                 ' Get one at a time
  478.                 ms = timeGetTime()
  479.                 For i = 1 To cIter
  480.                     sieveBasExeP.ReInitialize
  481.                     Do
  482.                         iPrime = sieveBasExeP.NextPrime
  483.                         If fDisplay And iPrime Then
  484.                             lstOutput.AddItem iPrime
  485.                             lstOutput.TopIndex = lstOutput.ListCount - 1
  486.                             lstOutput.Refresh
  487.                         End If
  488.                     Loop Until iPrime = 0
  489.                 Next
  490.                 txtTime.Text = timeGetTime() - ms
  491.                 txtPrimes.Text = sieveBasExeP.Primes
  492.             Else
  493.                 ' Get all at once
  494.                 ms = timeGetTime()
  495.                 For i = 1 To cIter
  496.                     ReDim ai(0 To cPrimeMax)
  497.                     sieveBasExeP.AllPrimes ai()
  498.                     If fDisplay Then
  499.                         For iPrime = 0 To sieveBasExeP.Primes - 1
  500.                             lstOutput.AddItem ai(iPrime)
  501.                         Next
  502.                     End If
  503.                 Next
  504.                 txtTime.Text = timeGetTime() - ms
  505.                 txtPrimes.Text = sieveBasExeP.Primes
  506.             End If
  507.         Case estBasicExeNative
  508.             ' Basic native EXE version, early bind
  509.             Dim sieveBasExeN As New CSieveBasExeN
  510.             sieveBasExeN.MaxPrime = txtMaxPrime.Text
  511.             If chkAll = vbUnchecked Then
  512.                 ' Get one at a time
  513.                 ms = timeGetTime()
  514.                 For i = 1 To cIter
  515.                     sieveBasExeN.ReInitialize
  516.                     Do
  517.                         iPrime = sieveBasExeN.NextPrime
  518.                         If fDisplay And iPrime Then
  519.                             lstOutput.AddItem iPrime
  520.                             lstOutput.TopIndex = lstOutput.ListCount - 1
  521.                             lstOutput.Refresh
  522.                         End If
  523.                     Loop Until iPrime = 0
  524.                 Next
  525.                 txtTime.Text = timeGetTime() - ms
  526.                 txtPrimes.Text = sieveBasExeN.Primes
  527.             Else
  528.                 ' Get all at once
  529.                 ms = timeGetTime()
  530.                 For i = 1 To cIter
  531.                     ReDim ai(0 To cPrimeMax)
  532.                     sieveBasExeN.AllPrimes ai()
  533.                     If fDisplay Then
  534.                         For iPrime = 0 To sieveBasExeN.Primes - 1
  535.                             lstOutput.AddItem ai(iPrime)
  536.                         Next
  537.                     End If
  538.                 Next
  539.                 txtTime.Text = timeGetTime() - ms
  540.                 txtPrimes.Text = sieveBasExeN.Primes
  541.             End If
  542.         Case estCppATL
  543.             Dim sieveAtl As New CSieveATL
  544.             sieveAtl.MaxPrime = txtMaxPrime.Text
  545.             If chkAll = vbUnchecked Then
  546.                 ' Get one at a time
  547.                 ms = timeGetTime()
  548.                 For i = 1 To cIter
  549.                     sieveAtl.ReInitialize
  550.                     Do
  551.                         iPrime = sieveAtl.NextPrime
  552.                         If fDisplay And iPrime Then
  553.                             lstOutput.AddItem iPrime
  554.                             lstOutput.TopIndex = lstOutput.ListCount - 1
  555.                             lstOutput.Refresh
  556.                         End If
  557.                     Loop Until iPrime = 0
  558.                 Next
  559.                 txtTime.Text = timeGetTime() - ms
  560.                 txtPrimes.Text = sieveAtl.Primes
  561.             Else
  562.                 ' Get all at once
  563.                 ms = timeGetTime()
  564.                 For i = 1 To cIter
  565.                     ReDim ai(0 To cPrimeMax)
  566.                     sieveAtl.AllPrimes ai()
  567.                     If fDisplay Then
  568.                         For iPrime = 0 To sieveAtl.Primes - 1
  569.                             lstOutput.AddItem ai(iPrime)
  570.                         Next
  571.                     End If
  572.                 Next
  573.                 txtTime.Text = timeGetTime() - ms
  574.                 txtPrimes.Text = sieveAtl.Primes
  575.             End If
  576.         Case estCppMFC
  577.             Dim SieveMFC As New CSieveMFC
  578.             SieveMFC.MaxPrime = txtMaxPrime.Text
  579.             If chkAll = vbUnchecked Then
  580.                 ' Get one at a time
  581.                 ms = timeGetTime()
  582.                 For i = 1 To cIter
  583.                     SieveMFC.ReInitialize
  584.                     Do
  585.                         iPrime = SieveMFC.NextPrime
  586.                         If fDisplay And iPrime Then
  587.                             lstOutput.AddItem iPrime
  588.                             lstOutput.TopIndex = lstOutput.ListCount - 1
  589.                             lstOutput.Refresh
  590.                         End If
  591.                     Loop Until iPrime = 0
  592.                 Next
  593.                 txtTime.Text = timeGetTime() - ms
  594.                 txtPrimes.Text = SieveMFC.Primes
  595.             Else
  596.                 ' Get all at once
  597.                 ms = timeGetTime()
  598.                 For i = 1 To cIter
  599.                     ReDim ai(0 To cPrimeMax)
  600.                     ' Put array in Variant for MFC
  601.                     vai = ai()
  602.                     SieveMFC.AllPrimes vai
  603.                     If fDisplay Then
  604.                         For iPrime = 0 To SieveMFC.Primes - 1
  605.                             lstOutput.AddItem ai(iPrime)
  606.                         Next
  607.                     End If
  608.                 Next
  609.                 txtTime.Text = timeGetTime() - ms
  610.                 txtPrimes.Text = SieveMFC.Primes
  611.             End If
  612.         End Select
  613.     Else ' Late bound
  614.         ' Set variable at run time
  615.         Dim sieveLate As Object
  616.         Select Case cboServer.ListIndex
  617.         Case estBasicLocalClass
  618.             Set sieveLate = New CSieve
  619. #Const fUseTypeLib = 1
  620. #If fUseTypeLib Then
  621.         Case estBasicDllPCode
  622.             Set sieveLate = New CSieveBasDllP
  623.         Case estBasicDllNative
  624.             Set sieveLate = New CSieveBasDllN
  625.         Case estBasicExePCode
  626.             Set sieveLate = New CSieveBasExeP
  627.         Case estBasicExeNative
  628.             Set sieveLate = New CSieveBasExeN
  629.         Case estCppATL
  630.             Set sieveLate = New CSieveATL
  631.         Case estCppMFC
  632.             Set sieveLate = New CSieveMFC
  633. #Else
  634.         Case estBasicEXE
  635.             Set sieveLate = CreateObject("SieveBasDllP.CSieveBasDllP")
  636.         Case estBasicDllNative
  637.             Set sieveLate = CreateObject("SieveBasDllN.CSieveBasDllN")
  638.         Case estBasicExePCode
  639.             Set sieveLate = CreateObject("SieveBasExeP.CSieveBasExeP")
  640.         Case estBasicExeNative
  641.             Set sieveLate = CreateObject("SieveBasExeN.CSieveBasExeN")
  642.         Case estCppATL
  643.             Set sieveLate = CreateObject("SieveAtl.CSieveATL")
  644.         Case estCppMFC
  645.             Set sieveLate = CreateObject("SieveMFC.CSieveMFC")
  646. #End If
  647.         End Select
  648.         sieveLate.MaxPrime = txtMaxPrime.Text
  649.         If chkAll = vbUnchecked Then
  650.             ' Get one at a time
  651.             ms = timeGetTime()
  652.             For i = 1 To cIter
  653.                 sieveLate.ReInitialize
  654.                 Do
  655.                     iPrime = sieveLate.NextPrime
  656.                     If fDisplay And iPrime Then
  657.                         lstOutput.AddItem iPrime
  658.                         lstOutput.TopIndex = lstOutput.ListCount - 1
  659.                         lstOutput.Refresh
  660.                     End If
  661.                 Loop Until iPrime = 0
  662.             Next
  663.             txtTime.Text = timeGetTime() - ms
  664.             txtPrimes.Text = sieveLate.Primes
  665.         Else
  666.             ' Get all at once
  667.             If cboServer.ListIndex <> estCppMFC Then
  668.                 ms = timeGetTime()
  669.                 For i = 1 To cIter
  670.                     ReDim ai(0 To cPrimeMax)
  671.                     sieveLate.AllPrimes ai()
  672.                     If fDisplay Then
  673.                         For iPrime = 0 To sieveLate.Primes - 1
  674.                             lstOutput.AddItem ai(iPrime)
  675.                         Next
  676.                     End If
  677.                 Next
  678.                 txtTime.Text = timeGetTime() - ms
  679.             Else
  680.                 ' MFC different because it can't handle Basic arrays
  681.                 ms = timeGetTime()
  682.                 For i = 1 To cIter
  683.                     ReDim ai(0 To cPrimeMax)
  684.                     vai = ai()
  685.                     ' Put array in Variant for MFC
  686.                     sieveLate.AllPrimes vai
  687.                     If fDisplay Then
  688.                         For iPrime = 0 To sieveLate.Primes - 1
  689.                             lstOutput.AddItem ai(iPrime)
  690.                         Next
  691.                     End If
  692.                 Next
  693.                 txtTime.Text = timeGetTime() - ms
  694.             End If
  695.             txtPrimes.Text = sieveLate.Primes
  696.         End If
  697.     End If
  698.     MousePointer = mpcMouse
  699. End Sub
  700.  
  701. Sub RefreshControls()
  702.     fDisplay = (chkDisplay.Value = vbChecked)
  703.     If lstOutput.ListCount Then lstOutput.Clear
  704. End Sub
  705.  
  706.